//function parses mysql datetime string and returns javascript Date object
//input has to be in this format: 2007-06-05 15:26:02

function mysqlTimeStampToDate(timestamp)
{
    var regex = /^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
    var parts = timestamp.replace(regex, "$1 $2 $3 $4 $5 $6").split(' ');
    return new Date(parts[0], parts[1] - 1, parts[2], parts[3], parts[4], parts[5]);
}

// leading zero

function lz(_val)
{
    return (parseInt(_val, 10) < 10) ? ('0' + _val) : _val;
}

// return local format date and time

function localeDateTime(_date)
{
    return lz(_date.getDate()) 
            + '.' + lz(_date.getMonth()+1) 
            + '.' + _date.getFullYear() 
            + ' ' + lz(_date.getHours()) 
            + ':' + lz(_date.getMinutes()) 
            + ':' + lz(_date.getSeconds());
}
